package com.seamtop.cuber.core;

import com.seamtop.cuber.common.conf.CuberServerConfiger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.sql.*;
import java.util.Properties;

/**
 * Created by zongjunfeng on 2015/9/2.
 */
public class HiveManager {

    private static final Logger LOG = LoggerFactory.getLogger(HiveManager.class);

    private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
    private static String url = "jdbc:hive://"+CuberServerConfiger.serverConfigProperties.getProperty("hive.server")+"/default";
    private static String user = "hive";
    private static String password = "mysql";
    public static Connection getConnetion(){
        Connection conn = null;
            try {
                Class.forName(driverName);
                conn = DriverManager.getConnection(url,user,password);
                LOG.info("Get hive connect -- url:"+url + " conn:"+conn);
            }  catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        return conn;
    }

    public static void closeAll(ResultSet rs,PreparedStatement psmt,Connection conn){
        if(rs!=null){
            try {
                rs.close();
                rs=null;
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(psmt!=null){
            try {
                psmt.close();
                psmt=null;
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(conn!=null){
            try {
                conn.close();
                conn=null;
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }

    public static void main(String[] args) {
        getConnetion();
    }



}
